from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-26 14:02:22.835427
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 26, Jun, 2022
Time: 14:02:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6011
Nobs: 699.000 HQIC: -49.9604
Log likelihood: 8703.76 FPE: 1.60006e-22
AIC: -50.1869 Det(Omega_mle): 1.40804e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298915 0.057811 5.171 0.000
L1.Burgenland 0.107416 0.037980 2.828 0.005
L1.Kärnten -0.109443 0.020104 -5.444 0.000
L1.Niederösterreich 0.212881 0.079340 2.683 0.007
L1.Oberösterreich 0.103673 0.077859 1.332 0.183
L1.Salzburg 0.256874 0.040645 6.320 0.000
L1.Steiermark 0.045399 0.052914 0.858 0.391
L1.Tirol 0.109467 0.042945 2.549 0.011
L1.Vorarlberg -0.059022 0.037274 -1.583 0.113
L1.Wien 0.039166 0.068774 0.569 0.569
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050557 0.121298 0.417 0.677
L1.Burgenland -0.033920 0.079688 -0.426 0.670
L1.Kärnten 0.041294 0.042181 0.979 0.328
L1.Niederösterreich -0.168627 0.166469 -1.013 0.311
L1.Oberösterreich 0.425465 0.163362 2.604 0.009
L1.Salzburg 0.289466 0.085280 3.394 0.001
L1.Steiermark 0.100529 0.111022 0.905 0.365
L1.Tirol 0.318780 0.090105 3.538 0.000
L1.Vorarlberg 0.028459 0.078206 0.364 0.716
L1.Wien -0.044667 0.144299 -0.310 0.757
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187021 0.029622 6.314 0.000
L1.Burgenland 0.090922 0.019460 4.672 0.000
L1.Kärnten -0.007982 0.010301 -0.775 0.438
L1.Niederösterreich 0.266795 0.040653 6.563 0.000
L1.Oberösterreich 0.135479 0.039894 3.396 0.001
L1.Salzburg 0.046109 0.020826 2.214 0.027
L1.Steiermark 0.020142 0.027112 0.743 0.458
L1.Tirol 0.092003 0.022004 4.181 0.000
L1.Vorarlberg 0.056893 0.019098 2.979 0.003
L1.Wien 0.113858 0.035239 3.231 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112498 0.030064 3.742 0.000
L1.Burgenland 0.045600 0.019751 2.309 0.021
L1.Kärnten -0.013752 0.010455 -1.315 0.188
L1.Niederösterreich 0.191319 0.041259 4.637 0.000
L1.Oberösterreich 0.303615 0.040489 7.499 0.000
L1.Salzburg 0.107688 0.021137 5.095 0.000
L1.Steiermark 0.104071 0.027517 3.782 0.000
L1.Tirol 0.103665 0.022333 4.642 0.000
L1.Vorarlberg 0.068559 0.019383 3.537 0.000
L1.Wien -0.024121 0.035765 -0.674 0.500
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134365 0.054974 2.444 0.015
L1.Burgenland -0.050753 0.036116 -1.405 0.160
L1.Kärnten -0.044319 0.019117 -2.318 0.020
L1.Niederösterreich 0.156851 0.075446 2.079 0.038
L1.Oberösterreich 0.139084 0.074038 1.879 0.060
L1.Salzburg 0.285777 0.038650 7.394 0.000
L1.Steiermark 0.048494 0.050317 0.964 0.335
L1.Tirol 0.167402 0.040837 4.099 0.000
L1.Vorarlberg 0.093601 0.035444 2.641 0.008
L1.Wien 0.071892 0.065398 1.099 0.272
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054840 0.043707 1.255 0.210
L1.Burgenland 0.037720 0.028714 1.314 0.189
L1.Kärnten 0.051083 0.015199 3.361 0.001
L1.Niederösterreich 0.218400 0.059983 3.641 0.000
L1.Oberösterreich 0.293635 0.058864 4.988 0.000
L1.Salzburg 0.047677 0.030729 1.552 0.121
L1.Steiermark 0.001592 0.040004 0.040 0.968
L1.Tirol 0.140935 0.032467 4.341 0.000
L1.Vorarlberg 0.074225 0.028180 2.634 0.008
L1.Wien 0.080749 0.051995 1.553 0.120
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175639 0.052275 3.360 0.001
L1.Burgenland -0.002043 0.034343 -0.060 0.953
L1.Kärnten -0.063130 0.018179 -3.473 0.001
L1.Niederösterreich -0.080011 0.071742 -1.115 0.265
L1.Oberösterreich 0.193480 0.070403 2.748 0.006
L1.Salzburg 0.056761 0.036752 1.544 0.122
L1.Steiermark 0.236390 0.047846 4.941 0.000
L1.Tirol 0.498045 0.038832 12.826 0.000
L1.Vorarlberg 0.044572 0.033704 1.322 0.186
L1.Wien -0.057180 0.062187 -0.919 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170029 0.059446 2.860 0.004
L1.Burgenland -0.011773 0.039054 -0.301 0.763
L1.Kärnten 0.063881 0.020672 3.090 0.002
L1.Niederösterreich 0.206399 0.081584 2.530 0.011
L1.Oberösterreich -0.076854 0.080061 -0.960 0.337
L1.Salzburg 0.212381 0.041794 5.082 0.000
L1.Steiermark 0.125862 0.054410 2.313 0.021
L1.Tirol 0.067006 0.044159 1.517 0.129
L1.Vorarlberg 0.119508 0.038327 3.118 0.002
L1.Wien 0.125929 0.070718 1.781 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.364058 0.034400 10.583 0.000
L1.Burgenland 0.007043 0.022600 0.312 0.755
L1.Kärnten -0.023526 0.011963 -1.967 0.049
L1.Niederösterreich 0.216095 0.047211 4.577 0.000
L1.Oberösterreich 0.204534 0.046329 4.415 0.000
L1.Salzburg 0.043940 0.024185 1.817 0.069
L1.Steiermark -0.015176 0.031486 -0.482 0.630
L1.Tirol 0.105777 0.025554 4.139 0.000
L1.Vorarlberg 0.069731 0.022179 3.144 0.002
L1.Wien 0.029782 0.040923 0.728 0.467
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037635 0.136548 0.193644 0.155303 0.114443 0.101692 0.058127 0.216719
Kärnten 0.037635 1.000000 -0.014754 0.134198 0.055993 0.095537 0.436002 -0.053080 0.093477
Niederösterreich 0.136548 -0.014754 1.000000 0.337361 0.143208 0.294897 0.091870 0.177973 0.311650
Oberösterreich 0.193644 0.134198 0.337361 1.000000 0.228984 0.325387 0.176771 0.163966 0.264765
Salzburg 0.155303 0.055993 0.143208 0.228984 1.000000 0.139043 0.116984 0.140678 0.131785
Steiermark 0.114443 0.095537 0.294897 0.325387 0.139043 1.000000 0.145658 0.129600 0.073367
Tirol 0.101692 0.436002 0.091870 0.176771 0.116984 0.145658 1.000000 0.112963 0.141644
Vorarlberg 0.058127 -0.053080 0.177973 0.163966 0.140678 0.129600 0.112963 1.000000 0.004875
Wien 0.216719 0.093477 0.311650 0.264765 0.131785 0.073367 0.141644 0.004875 1.000000